package c.d.a.a.c;

import c.d.a.a.b.i.a;
import c.d.a.a.e.b;
import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* compiled from: ChartData */
public abstract class d<T extends c.d.a.a.f.b.d<? extends Entry>> {
    public float a;
    public float b;
    public float c;
    public float d;
    public float e;
    public float f;
    public float g;
    public float h;
    public List<T> i;

    public d() {
        this.a = -3.4028235E38f;
        this.b = Float.MAX_VALUE;
        this.c = -3.4028235E38f;
        this.d = Float.MAX_VALUE;
        this.e = -3.4028235E38f;
        this.f = Float.MAX_VALUE;
        this.g = -3.4028235E38f;
        this.h = Float.MAX_VALUE;
        this.i = new ArrayList();
    }

    public void a() {
        a aVar = a.RIGHT;
        a aVar2 = a.LEFT;
        List<c.d.a.a.f.b.d> list = this.i;
        if (list != null) {
            c.d.a.a.f.b.d dVar;
            c.d.a.a.f.b.d dVar2;
            this.a = -3.4028235E38f;
            this.b = Float.MAX_VALUE;
            this.c = -3.4028235E38f;
            this.d = Float.MAX_VALUE;
            for (c.d.a.a.f.b.d b : list) {
                b(b);
            }
            this.e = -3.4028235E38f;
            this.f = Float.MAX_VALUE;
            this.g = -3.4028235E38f;
            this.h = Float.MAX_VALUE;
            Iterator it = this.i.iterator();
            do {
                dVar2 = null;
                if (!it.hasNext()) {
                    dVar = null;
                    break;
                }
                dVar = (c.d.a.a.f.b.d) it.next();
            } while (dVar.e0() != aVar2);
            if (dVar != null) {
                this.e = dVar.t();
                this.f = dVar.R();
                for (c.d.a.a.f.b.d dVar3 : this.i) {
                    if (dVar3.e0() == aVar2) {
                        if (dVar3.R() < this.f) {
                            this.f = dVar3.R();
                        }
                        if (dVar3.t() > this.e) {
                            this.e = dVar3.t();
                        }
                    }
                }
            }
            for (c.d.a.a.f.b.d dVar4 : this.i) {
                if (dVar4.e0() == aVar) {
                    dVar2 = dVar4;
                    break;
                }
            }
            if (dVar2 != null) {
                this.g = dVar2.t();
                this.h = dVar2.R();
                for (c.d.a.a.f.b.d dVar42 : this.i) {
                    if (dVar42.e0() == aVar) {
                        if (dVar42.R() < this.h) {
                            this.h = dVar42.R();
                        }
                        if (dVar42.t() > this.g) {
                            this.g = dVar42.t();
                        }
                    }
                }
            }
        }
    }

    public void b(T t) {
        if (this.a < t.t()) {
            this.a = t.t();
        }
        if (this.b > t.R()) {
            this.b = t.R();
        }
        if (this.c < t.P()) {
            this.c = t.P();
        }
        if (this.d > t.o()) {
            this.d = t.o();
        }
        if (t.e0() == a.LEFT) {
            if (this.e < t.t()) {
                this.e = t.t();
            }
            if (this.f > t.R()) {
                this.f = t.R();
                return;
            }
            return;
        }
        if (this.g < t.t()) {
            this.g = t.t();
        }
        if (this.h > t.R()) {
            this.h = t.R();
        }
    }

    public T c(int i) {
        List list = this.i;
        return (list == null || i < 0 || i >= list.size()) ? null : (c.d.a.a.f.b.d) this.i.get(i);
    }

    public int d() {
        List list = this.i;
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public int e() {
        int i = 0;
        for (c.d.a.a.f.b.d i0 : this.i) {
            i += i0.i0();
        }
        return i;
    }

    public Entry f(b bVar) {
        if (bVar.f >= this.i.size()) {
            return null;
        }
        return ((c.d.a.a.f.b.d) this.i.get(bVar.f)).D(bVar.a, bVar.b);
    }

    public T g() {
        List list = this.i;
        if (list == null || list.isEmpty()) {
            return null;
        }
        T t = (c.d.a.a.f.b.d) this.i.get(0);
        for (T t2 : this.i) {
            if (t2.i0() > t.i0()) {
                t = t2;
            }
        }
        return t;
    }

    public float h(a aVar) {
        float f;
        if (aVar == a.LEFT) {
            f = this.e;
            if (f == -3.4028235E38f) {
                f = this.g;
            }
            return f;
        }
        f = this.g;
        if (f == -3.4028235E38f) {
            f = this.e;
        }
        return f;
    }

    public float i(a aVar) {
        float f;
        if (aVar == a.LEFT) {
            f = this.f;
            if (f == Float.MAX_VALUE) {
                f = this.h;
            }
            return f;
        }
        f = this.h;
        if (f == Float.MAX_VALUE) {
            f = this.f;
        }
        return f;
    }

    public d(T... tArr) {
        this.a = -3.4028235E38f;
        this.b = Float.MAX_VALUE;
        this.c = -3.4028235E38f;
        this.d = Float.MAX_VALUE;
        this.e = -3.4028235E38f;
        this.f = Float.MAX_VALUE;
        this.g = -3.4028235E38f;
        this.h = Float.MAX_VALUE;
        ArrayList arrayList = new ArrayList();
        for (Object add : tArr) {
            arrayList.add(add);
        }
        this.i = arrayList;
        a();
    }
}
